package com.crm.service.impl.orderManager;

import com.crm.dao.mapper.customMapper.customerManagerCustomMapper.CustomerOrderBackMoneyCustomMapper;
import com.crm.dao.mapper.customMapper.orderManagerCustomMapper.CustomerProductOrderCustomMapper;
import com.crm.dao.mapper.customMapper.returnMoneyManagerCustomMapper.ReturnMoneyCustomMapper;
import com.crm.dao.mapper.customerManager.CustomerOrderBackMoneyExamineMapper;
import com.crm.dao.mapper.customerManager.CustomerOrderBackMoneyMapper;
import com.crm.dao.mapper.orderManager.CustomerProductOrderMapper;
import com.crm.model.entity.customerManager.CustomerOrderBackMoney;
import com.crm.model.entity.customerManager.CustomerOrderBackMoneyExamine;
import com.crm.model.entity.customerManager.CustomerOrderBackMoneyExamineExample;
import com.crm.model.entity.customerManager.CustomerOrderBackMoneyExample;
import com.crm.model.entity.finishOrderProduct.FinishOrderProduct;
import com.crm.model.entity.orderManager.CustomerProductOrder;
import com.crm.model.entity.orderManager.CustomerProductOrderExample;
import com.crm.model.entity.returnMoney.ReturnMoney;
import com.crm.model.entity.sys.UserAccount;
import com.crm.model.qo.customerManager.OrderBackMoneyQO;
import com.crm.model.qo.orderManager.CustomerProductOrderQO;
import com.crm.model.qo.orderManager.ExportOrderProductQO;
import com.crm.model.qo.orderManager.FinanceProductOrderQO;
import com.crm.model.vo.customerManager.BalanceBackMoneyVO;
import com.crm.model.vo.customerManager.CustomerOrderBackMoneyVO;
import com.crm.model.vo.datasearch.DataSearchResultVO;
import com.crm.model.vo.orderManager.*;
import com.crm.model.vo.returnMoney.FinanceProductOderInfoVO;
import com.crm.service.orderManager.CustomerProductOrderDbService;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * @ Author ：pym
 * @ Date   ：2021/3/12 10:40
 */
@Service
public class CustomerProductOrderDbServiceImpl implements CustomerProductOrderDbService {
    @Autowired
    private CustomerProductOrderCustomMapper customerProductOrderCustomMapper;

    @Autowired
    private CustomerProductOrderMapper customerProductOrderMapper;

    @Autowired
    private CustomerOrderBackMoneyMapper customerOrderBackMoneyMapper;

    @Autowired
    private CustomerOrderBackMoneyCustomMapper customerOrderBackMoneyCustomMapper;

    @Autowired
    private CustomerOrderBackMoneyExamineMapper customerOrderBackMoneyExamineMapper;

    @Autowired
    private ReturnMoneyCustomMapper returnMoneyCustomMapper;

    /**
     * 订单管理-订单列表
     * @Author pym
     * @Date  2021/3/12 11:18
     * @param customerProductOrderQO -查询条件
     * @param dateUnit -日期类型(全部/本周/本月/本年度)
     * @param accountId -账号Id
     * @param companyId -所属分公司Id
     * @return {@link {java.util.List<com.crm.model.vo.orderManager.CustomerProductOrderVO>}}
     */
    @Override
    public List<CustomerProductOrderVO> selectAllCustomerProductOrderList(CustomerProductOrderQO customerProductOrderQO,
                                                                          Integer dateUnit, String order, String accountId,
                                                                          String companyId) {
        return customerProductOrderCustomMapper.selectAllCustomerProductOrderList(customerProductOrderQO, dateUnit, order, accountId, companyId);
    }

    /**
     * 订单详情基本信息
     * @Author pym
     * @Date  2021/3/17 14:09
     * @param productOrderId
     * @return {@link {com.crm.model.vo.orderManager.OrderDetailVO}}
     */
    @Override
    public OrderDetailVO selectOrderDetailVO(String productOrderId) {
        return customerProductOrderCustomMapper.selectOrderDetailVO(productOrderId);
    }

    /**
     * 新建合同--新增订单
     * @param customerProductOrder 订单Model
     * @author luojie
     * @return
     */
    @Override
    public Boolean insertProductOrder(CustomerProductOrder customerProductOrder) {
        int num = customerProductOrderMapper.insertSelective(customerProductOrder);
        return num>0;
    }

    /**
     * 根据合同ID修改订单状态(合同列表--作废->未生效的合同可以作废)
     * @param contractId ---合同ID
     * @author yincuimei
     * @return
     */
    @Override
    public Boolean updateOrderStatusByContractId(String contractId){
        /**订单修改信息**/
        UserAccount userAccount = (UserAccount) SecurityUtils.getSubject().getPrincipal();//获取登录人信息
        CustomerProductOrder customerProductOrder = new CustomerProductOrder();
        customerProductOrder.setOrderStatus("3");//订单状态
        customerProductOrder.setUpdateTm(new Date());//更新时间
        customerProductOrder.setUpdatePeopleId(userAccount.getAccountId());//更新人ID

        /**订单修改过滤条件**/
        CustomerProductOrderExample productOrderExample = new CustomerProductOrderExample();
        CustomerProductOrderExample.Criteria criteria = productOrderExample.createCriteria();
        criteria.andContractIdEqualTo(contractId);//合同ID
        return customerProductOrderMapper.updateByExampleSelective(customerProductOrder,productOrderExample) > 0;
    }

    /**
     * 财务-订单列表
     * @param financeProductOrderQO
     * @param dateUnit
     * @param order
     * @param companyId
     * @return
     */
    @Override
    public List<FinanceProductOrderVO> selectFinanceOrderVOList(FinanceProductOrderQO financeProductOrderQO, Integer dateUnit, String order, String companyId) {
        return customerProductOrderCustomMapper.selectFinanceOrderVOList(financeProductOrderQO,dateUnit,order,companyId);
    }

    /**
     * 财务-订单详情
     * @param productOrderId
     * @return
     */
    @Override
    public FinanceProductOderInfoVO getFinanceProductOderInfo(String productOrderId,Integer status,Integer type) {
        return customerProductOrderCustomMapper.getFinanceProductOderInfo(productOrderId,status,type);
    }

    @Override
    public CustomerProductOrder selectProductOrderByContractId(String contractId) {
        CustomerProductOrderExample productOrderExample = new CustomerProductOrderExample();
        CustomerProductOrderExample.Criteria criteria = productOrderExample.createCriteria();
        criteria.andContractIdEqualTo(contractId);
        List<CustomerProductOrder> customerProductOrderList = customerProductOrderMapper.selectByExample(productOrderExample);
        if(customerProductOrderList.size()>0){
            return customerProductOrderList.get(0);
        }else {
            return null;
        }
    }

    @Override
    public CustomerProductOrderVO getOrderInfoById(String orderId) {
        return customerProductOrderCustomMapper.getOrderInfoById(orderId);
    }

    /**
     * 通过订单编号查询订单信息
     * @param orderNumber
     * @return
     */
    @Override
    public CustomerProductOrderVO getOrderInfoByNumber(String orderNumber) {
        return customerProductOrderCustomMapper.getOrderInfoByNumber(orderNumber);
    }

    /**
     * 回款、修改订单表
     * @param order
     * @return
     */
    @Override
    public void updateOrderComplete(CustomerProductOrderVO order) {
        customerProductOrderCustomMapper.updateOrderComplete(order);
    }

    /**
     * 获取完成的订单的产品
     * @param orderId
     * @return
     */
    @Override
    public List<FinishOrderProduct> getFinishProductList(String orderId) {
        return customerProductOrderCustomMapper.getFinishProductList(orderId);
    }

    /**
     * 更新产品订单详情
     * @param customerProductOrder 订单model
     * @return
     */
    @Override
    public Boolean updateProductOrder(CustomerProductOrder customerProductOrder) {
        int num = customerProductOrderMapper.updateByPrimaryKeySelective(customerProductOrder);
        return num>0;
    }

    /**
     * 根据订单id查询订单信息
     * @param orderId 订单id
     * @return
     */
    @Override
    public CustomerProductOrder selectCustomerProductOrderById(String orderId) {
        CustomerProductOrder customerProductOrder = customerProductOrderMapper.selectByPrimaryKey(orderId);
        return customerProductOrder;
    }

    /**
     * 申请开票页面订单详情
     * @param type
     * @param orderId
     * @return
     */
    @Override
    public ApplyInvoiceOrderInfoVO getApplyInvoiceOrderInfo(String type, String orderId) {
        return customerProductOrderCustomMapper.getApplyInvoiceOrderInfo(type,orderId);
    }

    /**
     * 统计会员消费占比
     * @param year 年份
     * @return
     */
    @Override
    public List<Integer> getAnalyseVipBuyRatio(Integer year,String companyId) {
        return customerProductOrderCustomMapper.getAnalyseVipBuyRatio(year,companyId);
    }

    /**
     * 会员复购率
     * @param year 年份
     * @param companyId
     * @return
     */
    @Override
    public List<Integer> getAnalyseVipAgainBuyRatio(Integer year, String companyId) {
        return customerProductOrderCustomMapper.getAnalyseVipAgainBuyRatio(year,companyId);
    }

    /**
     * 会员交易增长率
     * @param year
     * @param companyId
     * @return
     */
    @Override
    public List<BigDecimal> getAnalyseVipBuyRiseRatio(Integer year, String companyId) {
        return customerProductOrderCustomMapper.getAnalyseVipBuyRiseRatio(year,companyId);
    }


    /**
     * 客户详情订单信息
     * @param order 分组类型
     * @param customerId 客户id
     * @return
     */
    @Override
    public List<CustomerProductOrder> orderList(String order, String customerId,String accountId) {
        CustomerProductOrderExample productOrderExample = new CustomerProductOrderExample();
        productOrderExample.setOrderByClause(order);
        CustomerProductOrderExample.Criteria criteria = productOrderExample.createCriteria();
        criteria.andCustomerIdEqualTo(customerId);
        criteria.andCreatePeopleIdEqualTo(accountId);
        List<CustomerProductOrder> customerProductOrderList = customerProductOrderMapper.selectByExample(productOrderExample);
        return customerProductOrderList;
    }

    /***
     * @Description:会员非会员总额度统计
     * @Param:yearMark 查询月份(传12是今年，传24是去年)
     * @Author: luojie
     * @Date: 2021/4/27 22:26
     */
    @Override
    public BigDecimal selectAnnualAmountByOneMonth(String yeahMonth,String memberTag,String accountId) {
        BigDecimal count = customerProductOrderCustomMapper.selectAnnualAmountByOneMonth(yeahMonth, memberTag, accountId);
        return count;
    }

    /***
     * @Description: 查询公司本月金额统计
     * @Param: companyId 公司id
     * @Author: luojie
     * @Date: 2021/4/27 22:58
     */
    @Override
    public BigDecimal selectThisMonthCompanyPerformance(String companyId,String thisMonth) {
        BigDecimal result = customerProductOrderCustomMapper.selectThisMonthCompanyPerformance(companyId,thisMonth);
        return result;
    }

    /***
     * @Description:查询个人本月金额统计
     * @Param: accountId 账号id
     * @Author: luojie
     * @Date: 2021/4/27 22:59
     */
    @Override
    public BigDecimal selectThisMonthPersonalPerformance(String accountId,String thisMonth) {
        BigDecimal result = customerProductOrderCustomMapper.selectThisMonthPersonalPerformance(accountId,thisMonth);
        return result;
    }

    /***
     * @Description:查询业绩排名
     * @Author: luojie
     * @Date: 2021/4/29 9:23
     */
    @Override
    public List<PerformanceRankVO> selectPerformanceRank(String companyId) {
        List<PerformanceRankVO> performanceRank = customerProductOrderCustomMapper.selectPerformanceRank(companyId);
        return performanceRank;
    }

    /***
     * @Description:查询个人本月业绩统计
     * @Param: companyId 公司id
     * @Param: accountId 账号id
     * @Param: thisMonth 本月
     * @Author: luojie
     * @Date: 2021/4/29 11:30
     */
    @Override
    public int personalThisMonthPerformanceRank(String companyId, String accountId, String thisMonth) {
        int personPerformanceRank = customerProductOrderCustomMapper.personalThisMonthPerformanceRank(companyId,accountId,thisMonth);
        return personPerformanceRank;
    }

    /**
     * 根据账号和是否生效状态查询合同
     * @param orderStatus 合同状态 1未生效；3:已结束（生效）；4:已作废
     * @param dateUnit:
     * @param accountId 账号id
     * @Author: luojie
     * @return
     */
    @Override
    public BigDecimal selectContractAmount(String orderStatus,Integer dateUnit, String accountId) {
        BigDecimal contractAmount = customerProductOrderCustomMapper.selectContractAmount(orderStatus,dateUnit,accountId);
        return contractAmount;
    }

    /**
     * 根据账号和是否生效状态查询合同数量
     * @param orderStatus 合同状态
     * @param dateUnit contractStatus:1未生效；3:已结束（生效）；4:已作废
     * @param accountId 账号id
     * @Author: luojie
     * @return
     */
    @Override
    public long selectContractCount(String orderStatus, Integer dateUnit, String accountId) {
        long contractCount = customerProductOrderCustomMapper.selectContractCount(orderStatus,dateUnit,accountId);
        return contractCount;
    }

    /***
     * @Description:查询合同退款数
     * @Param: dateUnit  ---全部、本周、本月查询条件
     * @Param: accountId 账号id
     * @Author: luojie
     * @Date: 2021/5/6 10:24
     */
    @Override
    public long selectContractRefundCount(Integer dateUnit, String accountId) {
        long contractRefundCount = customerProductOrderCustomMapper.selectContractRefundCount(dateUnit,accountId);
        return contractRefundCount;
    }


    /**
     * @Description: 通过订单编号获取数据
     * @Param: [orderNum]
     * @Return: java.util.List<com.crm.model.vo.datasearch.DataSearchResultVO>
     * @Author: lixq-f
     * @Date: 2021/5/13
     **/
    @Override
    public List<DataSearchResultVO> selectDataByOrderNum(String orderNum) {
        return customerProductOrderCustomMapper.selectDataByOrderNum(orderNum);
    }

    /**
     * 更新订单表全部字段
     * @param order
     */
    @Override
    public void updateByPrimaryKey(CustomerProductOrder order) {
        customerProductOrderMapper.updateByPrimaryKey(order);
    }

    /**
     * 部分更新订单表
     * @param order
     */
    @Override
    public Boolean updateByPrimaryKeySelective(CustomerProductOrder order) {
        int num = customerProductOrderMapper.updateByPrimaryKeySelective(order);
        return num > 0;
    }

    /**
     * 根据订单编号判断订单是否重复
     * @Author pym
     * @Date  2021/6/1 15:42
     * @param orderNumber 订单编号
     * @return {@link {com.crm.model.entity.orderManager.CustomerProductOrder}}
     */
    @Override
    public CustomerProductOrder isCustomerProductOrderRepeat(String orderNumber) {
        CustomerProductOrderExample customerProductOrderExample = new CustomerProductOrderExample();
        CustomerProductOrderExample.Criteria criteria = customerProductOrderExample.createCriteria();
        criteria.andOrderNumberEqualTo(orderNumber);
        List<CustomerProductOrder> customerProductOrderList = customerProductOrderMapper.selectByExample(customerProductOrderExample);
        if (customerProductOrderList != null && customerProductOrderList.size() > 0) {
            return customerProductOrderList.get(0);
        }
        return null;
    }

    /**
     * 根据订单编号查询
     * @param orderNumber
     * @return
     */
    @Override
    public CustomerProductOrderVO selectOrderByNumber(String orderNumber) {
        return customerProductOrderCustomMapper.selectOrderByNumber(orderNumber);
    }

    /**
     * 根据月份查询公司的交易额
     * @param companyId
     * @param thisMonth
     * @return
     */
    @Override
    public BigDecimal selectThisMonthBigByCompanyId(String companyId, String thisMonth) {
        return customerProductOrderCustomMapper.selectThisMonthBigByCompanyId(companyId,thisMonth);
    }

    /**
     * 查询会员总数
     * @param companyId
     * @return
     */
    @Override
    public Integer selectCustomerCount(String companyId) {
        return customerProductOrderCustomMapper.selectCustomerCount(companyId);
    }

    /**
     * 当月客户消费额度
     * @param month
     * @param companyId
     * @return
     */
    @Override
    public BigDecimal getThisMonthCustomerConsumeCount(String month, String companyId) {
        return customerProductOrderCustomMapper.getThisMonthCustomerConsumeCount(month,companyId);
    }

    /**
     * 当月会员客户消费额度
     * @param month
     * @param companyId
     * @return
     */
    @Override
    public BigDecimal getThisMonthVipCustomerConsumeCount(String month, String companyId) {
        return customerProductOrderCustomMapper.getThisMonthVipCustomerConsumeCount(month,companyId);
    }

    /**
     * 当月续费会员数量
     * @param month
     * @param companyId
     * @return
     */
    @Override
    public Integer selectThisMonthRenewVip(String month, String companyId) {
        return customerProductOrderCustomMapper.selectThisMonthRenewVip(month,companyId);
    }

    /**
     * 新增退款信息
     * @param customerOrderBackMoney 退款类
     * @return
     */
    @Override
    public Boolean addCustomerOrderBackMoney(CustomerOrderBackMoney customerOrderBackMoney) {
        Boolean result = false;
        int num = customerOrderBackMoneyMapper.insertSelective(customerOrderBackMoney);
        if(num>0){
            result = true;
        }
        return result;
    }

    /**
     * 管理员-退款列表
     * @Author bj
     * @Date  2021/7/27 9:27
     */
    @Override
    public List<CustomerOrderBackMoneyVO> customerOrderBackMoneyList(OrderBackMoneyQO orderBackMoneyQO) {
        return customerOrderBackMoneyCustomMapper.customerOrderBackMoneyList(orderBackMoneyQO);
    }

    /**
     * 普通用户-退款列表
     * @Author bj
     * @Date  2021/7/27 9:27
     */
    @Override
    public List<CustomerOrderBackMoneyVO> userCustomerOrderBackMoneyList(OrderBackMoneyQO orderBackMoneyQO) {
        return customerOrderBackMoneyCustomMapper.userCustomerOrderBackMoneyList(orderBackMoneyQO);
    }

    /**
     * 退款产品表-通过主键id查询
     * @param orderBackMoneyId 退款id
     * @return
     */
    @Override
    public CustomerOrderBackMoney getCustomerOrderMoneyDetail(String orderBackMoneyId) {
        return customerOrderBackMoneyMapper.selectByPrimaryKey(orderBackMoneyId);
    }

    /**
     * 修改退款记录
     * @param customerOrderBackMoney 退款产品记录
     * @return
     */
    @Override
    public Boolean updateCustomerOrderBackMoney(CustomerOrderBackMoney customerOrderBackMoney) {
        Boolean result = false;
        int num = customerOrderBackMoneyMapper.updateByPrimaryKeySelective(customerOrderBackMoney);
        if(num>0){
            result = true;
        }
        return result;
    }

    /**
     * 通过产品明细id查询退款表查询是否存在,防止重复提交退款
     * @param productOrderDetailId 产品明细id
     * @return
     */
    @Override
    public CustomerOrderBackMoney selectCustomerOrderBackMoneyByDetailId(String productOrderDetailId,Integer backStatus) {
        CustomerOrderBackMoneyExample customerOrderBackMoneyExample = new CustomerOrderBackMoneyExample();
        CustomerOrderBackMoneyExample.Criteria criteria = customerOrderBackMoneyExample.createCriteria();
        //criteria.andProductOrderDetailIdEqualTo(productOrderDetailId);
        criteria.andBackStatusEqualTo(backStatus);
        criteria.andDeleteStatusEqualTo(0);
        List<CustomerOrderBackMoney> list = customerOrderBackMoneyMapper.selectByExample(customerOrderBackMoneyExample);
        if (list != null && list.size() > 0) {
            return list.get(0);
        }
        return null;
    }

    /**
     * 订单详情-退款信息
     * @Author bj
     * @Date  2021/7/27 9:27
     */
    @Override
    public List<CustomerOrderBackMoneyVO> orderBackMoneyList(String productOrderId) {
        return customerOrderBackMoneyCustomMapper.orderBackMoneyList(productOrderId);
    }

    /**
     * 查询兑换码发送状态的订单
     * @param productOrderId 订单id
     * @param exchangeCodeSendingStatus
     * @return
     */
    @Override
    public CustomerProductOrder selectProductOrderAndSendStatus(String productOrderId, int exchangeCodeSendingStatus) {
        CustomerProductOrderExample productOrderExample = new CustomerProductOrderExample();
        CustomerProductOrderExample.Criteria criteria = productOrderExample.createCriteria();
        criteria.andProductOrderIdEqualTo(productOrderId);
        criteria.andExchangeCodeSendingStatusEqualTo(exchangeCodeSendingStatus);
        List<CustomerProductOrder> list = customerProductOrderMapper.selectByExample(productOrderExample);
        if(list != null && list.size() > 0){
            return list.get(0);
        }else{
            return null;
        }

    }

    /**
     * 通过订单id查询订单信息
     * @param productOrderId 订单id
     */
    @Override
    public CustomerProductOrder selectProductOrderById(String productOrderId) {
        return customerProductOrderMapper.selectByPrimaryKey(productOrderId);
    }

    /**
     * 查询需要补发产品的订单
     * @return
     */
    @Override
    public List<String> selectAnewSendFinishOrderId() {
        return customerProductOrderCustomMapper.selectAnewSendFinishOrderId();
    }

    /**
     * 查询没有计算业绩金额的产品
     * @return
     */
    @Override
    public List<FinishOrderProduct> getFinishProductRoyaltyIsNullList() {
        return customerProductOrderCustomMapper.getFinishProductRoyaltyIsNullList();
    }

    /**
     * 通过产品号和退款状态查询退款信息
     * @param finishOrderProductNum 产品号
     * @return
     */
    @Override
    public List<CustomerOrderBackMoney> selectCustomerOrderBackMoneyByCph(String finishOrderProductNum,Integer bs) {
        /*CustomerOrderBackMoneyExample customerOrderBackMoneyExample = new CustomerOrderBackMoneyExample();
        CustomerOrderBackMoneyExample.Criteria criteria = customerOrderBackMoneyExample.createCriteria();
        criteria.andFinishOrderProductNumEqualTo(finishOrderProductNum);
        criteria.andBackStatusNotEqualTo(backStatus);
        criteria.andDeleteStatusEqualTo(0);
        List<CustomerOrderBackMoney> list = customerOrderBackMoneyMapper.selectByExample(customerOrderBackMoneyExample);
        if (list != null && list.size() > 0) {
            return list.get(0);
        }*/
        return customerOrderBackMoneyCustomMapper.selectCustomerOrderBackMoneyByCph(finishOrderProductNum,bs);
    }

    /**
     * 通过订单id和退款状态查询退款信息
     * @param productOrderId 订单id
     * @param backStatus 退款状态 审核中
     * @return
     */
    @Override
    public CustomerOrderBackMoney selectCustomerOrderBackMoneyByOrderId(String productOrderId, int backStatus) {
        CustomerOrderBackMoneyExample customerOrderBackMoneyExample = new CustomerOrderBackMoneyExample();
        CustomerOrderBackMoneyExample.Criteria criteria = customerOrderBackMoneyExample.createCriteria();
        criteria.andProductOrderIdEqualTo(productOrderId);
        criteria.andBackStatusEqualTo(backStatus);
        criteria.andDeleteStatusEqualTo(0);
        List<CustomerOrderBackMoney> list = customerOrderBackMoneyMapper.selectByExample(customerOrderBackMoneyExample);
        if (list != null && list.size() > 0) {
            return list.get(0);
        }
        return null;
    }

    /**
     * 查询订单已完成的附加费用
     * @param productName 产品名称
     * @param orderId 订单id
     * @return
     */
    @Override
    public CustomerOrderBackMoney selectBackMoneyFjfy(String productName, String orderId) {
        /*CustomerOrderBackMoneyExample customerOrderBackMoneyExample = new CustomerOrderBackMoneyExample();
        CustomerOrderBackMoneyExample.Criteria criteria = customerOrderBackMoneyExample.createCriteria();
        criteria.andProductNameEqualTo(productName);
        criteria.andProductOrderIdEqualTo(orderId);
        criteria.andBackStatusEqualTo(0);
        criteria.andBackStatusEqualTo(2);
        criteria.andDeleteStatusEqualTo(0);
        List<CustomerOrderBackMoney> list = customerOrderBackMoneyMapper.selectByExample(customerOrderBackMoneyExample);
        if (list != null && list.size() > 0) {
            return list.get(0);
        }*/
        return customerOrderBackMoneyCustomMapper.selectBackMoneyFjfy(productName,orderId);
    }

    /**
     * 获取产品名称表头
     * @Author pym
     * @Date  2021/8/13 10:39
     * @param type 类型 memberNew：会员新建订单；membershipRenewal：会员续费订单；course：课程订单；
     * @param exportOrderProductQO 筛选条件
     * @param companyId 公司id
     * @return {@link {java.util.List<java.lang.String>}}
     */
    @Override
    public List<String> getProductNameList(String type, ExportOrderProductQO exportOrderProductQO, String companyId) {
        return customerProductOrderCustomMapper.getProductNameList(type, exportOrderProductQO, companyId);
    }

    /**
     * 获取产品名称和价格
     * @Author pym
     * @Date  2021/8/13 10:39
     * @param type 类型 memberNew：会员新建订单；membershipRenewal：会员续费订单；course：课程订单；
     * @param exportOrderProductQO 筛选条件
     * @param companyId 公司id
     * @return {@link {java.util.List<com.crm.model.vo.orderManager.OrderProductPriceVO>}}
     */
    @Override
    public List<OrderProductPriceVO> getProductNameAndPriceList(String type, ExportOrderProductQO exportOrderProductQO, String companyId) {
        return customerProductOrderCustomMapper.getProductNameAndPriceList(type, exportOrderProductQO, companyId);
    }

    /**
     * 获取退款产品名称表头
     * @Author pym
     * @Date  2021/8/13 10:40
     * @param exportOrderProductQO 筛选条件
     * @param companyId 公司id
     * @return {@link {java.util.List<java.lang.String>}}
     */
    @Override
    public List<String> getRefundProductNameList(ExportOrderProductQO exportOrderProductQO, String companyId) {
        return customerProductOrderCustomMapper.getRefundProductNameList(exportOrderProductQO, companyId);
    }

    /**
     * 获取退款产品名称和价格
     * @Author pym
     * @Date  2021/8/13 10:40
     * @param exportOrderProductQO 筛选条件
     * @param companyId 公司id
     * @return {@link {java.util.List<com.crm.model.vo.orderManager.OrderProductPriceVO>}}
     */
    @Override
    public List<OrderProductPriceVO> getRefundProductNameAndPriceList(ExportOrderProductQO exportOrderProductQO, String companyId) {
        return customerProductOrderCustomMapper.getRefundProductNameAndPriceList(exportOrderProductQO, companyId);
    }

    /**
     * 财务首页订单数量统计
     * @param companyId
     * @return
     */
    @Override
    public FinanceIndexOrderInfoVO financeIndexOrderInfo(String companyId) {
        return customerProductOrderCustomMapper.financeIndexOrderInfo(companyId);
    }

    /**
     * 查询各订单类型的回款金额
     * @param companyId
     * @param dateType
     * @return
     */
    @Override
    public List<BigDecimal> selectOrderTypeReturnMoney(String companyId, Integer dateType,Integer type) {
        return customerProductOrderCustomMapper.selectOrderTypeReturnMoney(companyId,dateType,type);
    }

    /**
     * 查询退款审核表
     * @param orderBackMoneyId 退款id
     * @return
     */
    @Override
    public CustomerOrderBackMoneyExamine selectOrderBackMoneyExamine(String orderBackMoneyId) {
        CustomerOrderBackMoneyExamineExample customerOrderBackMoneyExamineExample = new CustomerOrderBackMoneyExamineExample();
        CustomerOrderBackMoneyExamineExample.Criteria criteria = customerOrderBackMoneyExamineExample.createCriteria();
        criteria.andOrderBackMoneyIdEqualTo(orderBackMoneyId);
        /*criteria.andFzExamineStatusEqualTo(2);
        criteria.andKfExamineStatusEqualTo(2);
        criteria.andXzExamineStatusEqualTo(2);
        criteria.andWlbExamineStatusEqualTo(2);
        criteria.andCwExamineStatusEqualTo(2);*/
        criteria.andDeleteStatusEqualTo(0);
        List<CustomerOrderBackMoneyExamine> list = customerOrderBackMoneyExamineMapper.selectByExample(customerOrderBackMoneyExamineExample);
        if (list != null && list.size() > 0) {
            return list.get(0);
        }
        return null;
    }

    /**
     * 新增退款审核表
     * @param examine 退款审核
     * @return
     */
    @Override
    public Boolean addCustomerOrderBackMoneyExamine(CustomerOrderBackMoneyExamine examine) {
        Boolean result = false;
        int num = customerOrderBackMoneyExamineMapper.insertSelective(examine);
        if(num>0){
            result = true;
        }
        return result;
    }

    /**
     * 修改退款审核表
     * @param examine 退款审核
     */
    @Override
    public Boolean updateCustomerOrderBackMoneyExamine(CustomerOrderBackMoneyExamine examine) {
        Boolean result = false;
        int num = customerOrderBackMoneyExamineMapper.updateByPrimaryKeySelective(examine);
        if(num>0){
            result = true;
        }
        return result;
    }

    /**
     * 总部财务退款列表
     * @param orderBackMoneyQO 退款信息
     * @return
     */
    @Override
    public List<CustomerOrderBackMoneyVO> superCustomerOrderBackMoneyList(OrderBackMoneyQO orderBackMoneyQO) {
        return customerOrderBackMoneyCustomMapper.superCustomerOrderBackMoneyList(orderBackMoneyQO);
    }

    @Override
    public CustomerOrderBackMoney selectCustomerOrderBackMoneyById(String orderBackMoneyId) {
        return customerOrderBackMoneyMapper.selectByPrimaryKey(orderBackMoneyId);
    }

    @Override
    public List<CustomerProductOrderVO> selectCustomerAllOrder(String orderStatus) {
        return customerProductOrderCustomMapper.selectCustomerAllOrder(orderStatus);
    }

    /**
     * 退款详情-订单详情
     * @param orderBackMoneyId 退款id
     * @return
     */
    @Override
    public OrderDetailVO selectBackOrderDetail(String orderBackMoneyId) {
        return customerProductOrderCustomMapper.selectBackOrderDetail(orderBackMoneyId);
    }

    /**
     * 余额退款详情
     * @param orderBackMoneyId 退款id
     * @return
     */
    @Override
    public BalanceBackMoneyVO selectBalanceBackMoneyDetail(String orderBackMoneyId) {
        return customerProductOrderCustomMapper.selectBalanceBackMoneyDetail(orderBackMoneyId);
    }

    /**
     * 补全之前退款的回款记录表
     */
    @Override
    public List<CustomerOrderBackMoney> repairReturnMoney() {
        return customerOrderBackMoneyCustomMapper.repairReturnMoney();
    }

    /**
     * 批量补充订单表客户信息(临时用补充正式库数据:customer_id;customer_name为空的)
     * @param customerProductOrderList
     * @author yincuimei
     * @Date(2021-9-26)
     * @return
     */
    @Override
    public Boolean batchUpdateCustomerProductOrderByIds(List<CustomerProductOrder> customerProductOrderList) {
        return customerProductOrderCustomMapper.batchUpdateCustomerProductOrderByIds(customerProductOrderList) > 0;
    }

    /**
     * 通过订单id和产品号查询退款金额累加
     * @param productOrderId 订单id
     * @param finishOrderProductNum 产品号
     * @return
     */
    @Override
    public BigDecimal sumBackMoney(String productOrderId, String finishOrderProductNum) {
        return customerProductOrderCustomMapper.sumBackMoney(productOrderId,finishOrderProductNum);
    }

    @Override
    public Boolean updateOrderSelective(CustomerProductOrder customerProductOrder) {
        return customerProductOrderCustomMapper.updateOrderSelective(customerProductOrder);
    }

    /**
     * 退款未审核
     * @Author renshaorong
     * @Date 2021/12/17
     * @return
     */
    @Override
    public Integer getcustomerProductOrderNum() {
        return customerOrderBackMoneyCustomMapper.getcustomerProductOrderNum();
    }


    @Override
    public boolean updateOrderCustom(CustomerProductOrder customerProductOrder) {
        return customerProductOrderCustomMapper.updateOrderCustom(customerProductOrder);
    }

    /**
     * 发放状态为已发放的
     * @param productOrderId 订单id
     * @param royaltyStatus 提成发放状态 0 未发放 1已发放
     * @return
     */
    @Override
    public ReturnMoney selectReturnByRoyaltyStatus(String productOrderId, int royaltyStatus) {
        return returnMoneyCustomMapper.selectReturnByRoyaltyStatus(productOrderId,royaltyStatus);
    }
}
